package ezXpns.storage.queries;

import java.util.Date;

import org.apache.lucene.search.NumericRangeQuery;

import ezXpns.BudgetChange;
import ezXpns.storage.Query;


//@author A0088827L
public class DateRangeQuery implements Query<BudgetChange> {
	
	public DateRangeQuery(Date from, Date to) {
		this.from = from;
		this.to = to;
		this.luceneQuery = 
			NumericRangeQuery.newLongRange(
				"date",
				from.getTime(),
				to.getTime(),
				true,
				true
			);
	}

	@Override
	public boolean apply(BudgetChange arg) {
		Date date = arg.getDate();
		return from.compareTo(date) <= 0 && date.compareTo(to) <= 0;
	}

	@Override
	public org.apache.lucene.search.Query asLuceneQuery() {
		return luceneQuery;
	}
	
	private Date from;
	private Date to;
	private NumericRangeQuery<Long> luceneQuery;
}
